package com.demo.pk.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.pk.common.utils.DataResult;
import com.demo.pk.entity.SysDept2Entity;
import com.demo.pk.service.SysDept2Service;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;



/**
 * 系统部门
 *
 * @author WBB
 * @email *****@mail.com
 * @date 2021-07-25 21:52:28
 */
@RequestMapping("/sysDept2")
@RestController
@Api(tags = "系统部门")
public class SysDept2Controller {
    @Resource
    private SysDept2Service sysDeptService;


    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @RequiresPermissions("sysDept2:add")
    @ResponseBody
    public DataResult add(@RequestBody SysDept2Entity sysDept){
        sysDeptService.save(sysDept);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    @RequiresPermissions("sysDept2:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        sysDeptService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    @RequiresPermissions("sysDept2:update")
    @ResponseBody
    public DataResult update(@RequestBody SysDept2Entity sysDept){
        sysDeptService.updateById(sysDept);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("/listByPage")
    @RequiresPermissions("sysDept2:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SysDept2Entity sysDept){
        Page page = new Page(sysDept.getPage(), sysDept.getLimit());
        LambdaQueryWrapper<SysDept2Entity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(SysDeptEntity::getId, sysDept.getId());
        IPage<SysDept2Entity> iPage = sysDeptService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
